package com.kaiwukj.android.ufamily.mvp.ui.page.home.keeper;

import android.os.Bundle;

import com.blankj.utilcode.util.StringUtils;
import com.kaiwukj.android.ufamily.R;
import com.kaiwukj.android.ufamily.app.base.review.BaseFragment;
import com.kaiwukj.android.ufamily.mvp.http.entity.event.KeeperEvent;
import com.kaiwukj.android.ufamily.mvp.ui.page.keeper.KeeperBindFragment;
import com.kaiwukj.android.ufamily.mvp.ui.page.keeper.KeeperIndexFragment;

import org.greenrobot.eventbus.Subscribe;

public class KeeperContainerFragment extends BaseFragment {

    private boolean hasKeeper = false;

    public static KeeperContainerFragment newInstance(boolean hasKeeper) {
        KeeperContainerFragment fragment = new KeeperContainerFragment();
        fragment.hasKeeper = hasKeeper;
        return fragment;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_keeper_container;
    }

    @Override
    protected void initView() {
        hasKeeper = !StringUtils.isEmpty(getApp().getUserInfo().getKeeperHxName());
        updateFragment();
    }

    @Override
    protected void initData(Bundle savedInstanceState) {

    }

    private void updateFragment() {
       /* if (hasKeeper) {
            loadRootFragment(R.id.fl_content, KeeperIndexFragment.newInstance());
        } else {
            loadRootFragment(R.id.fl_content, KeeperBindFragment.newInstance(0));
        }*/
    }

    @Subscribe
    public void onKeeperEvent(KeeperEvent event) {
        if (event.getCode() == KeeperEvent.UPDATE) {
            boolean flag = !StringUtils.isEmpty(event.getEvent());
            if (flag == hasKeeper) return;//状态不变 不更新页面

            hasKeeper = flag;
            updateFragment();
        }
    }
}
